package com.xagcdx.group1.web;


import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
import com.xagcdx.group1.bean.Depart;
import com.xagcdx.group1.bean.Job;
import com.xagcdx.group1.service.JobService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author grou1
 * @since 2020-06-09
 */
@RestController
@RequestMapping("/job")
public class JobController {

	@Autowired
	private JobService js;

	@RequestMapping("/listPage")
	public String listPage(Integer limit, Integer page, String did, String jobname,String tag) {

		Map<String, Object> result = new HashMap<String, Object>(10);
		result.put("count", js.counts(page, limit));
		result.put("msg", "");
		result.put("code", 0);
		result.put("data", js.jobListPage((page - 1) * limit, limit,did,jobname,tag));

		return new Gson().toJson(result);

	}
	
	@RequestMapping("/update")
	public String update(Job job) {
		boolean updateById = js.updateById(job);
		if(updateById) {
			return "1";
		}else {
			return "0";
		}
		
	}

	@RequestMapping("/add")
	public String add(Job job) {
		boolean save = js.save(job);
		if(save) {
			return "1";
		}else {
			return "0";
		}
	}


	@RequestMapping("/remove")
	public String remove(String jid) {
		boolean removeById = js.removeById(jid);
		if(removeById) {
			return "1";
		}else {
			return "0";
		}
		
	}
	@RequestMapping("/list")
	public String list() {
		return new Gson().toJson(js.list(null));
	}

	@RequestMapping("/departsel")
	public String departsel(String did) {
		
		return new Gson().toJson(js.jobDepartList(did));
	}
	
	
}

